package com.asa.mvvm_aop_frame.basic.aspect

import android.app.Application
import android.util.Log
import com.asa.mvvm_aop_frame.basic.AutoSize
import com.asa.mvvm_aop_frame.basic.BaseApp
import org.aspectj.lang.JoinPoint
import org.aspectj.lang.annotation.After
import org.aspectj.lang.annotation.Aspect

/**
 * create By：anderson
 * on 2022/4/27
 * desc:
 */
@Aspect
open class ApplicationAspect {


    @After("execution(* android.app.Application.onCreate())")
    open fun onCreateOfApplication(joinPoint:JoinPoint){
        if (joinPoint.`this` is Application){
            val application = joinPoint.`this` as Application
            val declaredMethod = application.javaClass.getDeclaredMethod("onCreate")
            var designWidthInDp = 360
            var designHeightInDp = 640
            for (annotation in declaredMethod.annotations) {
                if (annotation is AutoSize){
                    designWidthInDp = annotation.designWidthInDp
                    designHeightInDp = annotation.designHeightInDp
                    break
                }
            }
            BaseApp.instance.init(
                designWidthInDp,
                designHeightInDp
            )

        }
    }

}